<!doctype html>
<html>
  <head>
    <title>rabbit.js and Socket.IO publish/subscribe example</title>
    <script src="/socket.io/socket.io.js"></script>
  </head>
  <body>

    <p>
      If you <a href="index.html">open the page</a> in more than one
      tab or window, you'll see published messages are sent to each
      and every subscriber (but only the messages since it subscribed,
      of course).
    </p>

    <script>
      function message(obj){
        var el = document.createElement('p');
        el.innerHTML = '<em>' + esc(obj) + '</em>'
        document.getElementById('chat').appendChild(el);
        document.getElementById('chat').scrollTop = 1000000;
      }

      var conn = io.connect(window.location.href);

      function send(){
        var val = document.getElementById('text').value;
        conn.send(val);
      }

      function esc(msg){
        return msg.replace(/</g, '&lt;').replace(/>/g, '&gt;');
      };

      conn.on('message', function(obj){
        message(obj);
      });
    </script>

    <div id="chat"></div>
    <form id="form" onsubmit="send(); return false">
      <input type="text" autocomplete="off" id="text"><input type="submit" value="Send">
    </form>

    <style>
      #chat { height: 200px; overflow: auto; width: 400px; border: 1px solid #eee; font: 13px Helvetica, Arial; }
      #chat p { padding: 8px; margin: 0; }
      #chat p:nth-child(odd) { background: #F6F6F6; }
      #form { width: 380px; background: #333; padding: 5px 10px; }
      #form input[type=text] { width: 300px; padding: 5px; background: #fff; border: 1px solid #fff; }
      #form input[type=submit] { cursor: pointer; background: #999; border: none; padding: 6px 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px; margin-left: 5px; text-shadow: 0 1px 0 #fff; }
      #form input[type=submit]:hover { background: #A2A2A2; }
      #form input[type=submit]:active { position: relative; top: 2px; }
    </style>
    
  </body>
</html>
